/**
 * 
 */
package liwei;

import javax.swing.JTextArea;
import javax.swing.event.CaretEvent;
import javax.swing.event.CaretListener;
import javax.swing.undo.UndoManager;

/**
 * @author LiWei
 *
 */
public final class MainTextArea extends JTextArea
{

	/**
	 * the text area that contains the text input by the client
	 */
	public MainTextArea(final MyPanel myPanel,int width,int height)
	{
		super(width,height);
		setLineWrap(true);
		setTabSize(2);
		//when some letters are input,we will count the number of the words again.
		addCaretListener(new CaretListener()
		{
			
			@Override
			public void caretUpdate(CaretEvent arg0)
			{
				myPanel.wordCounter.Count(getText());
				int wordNum = myPanel.wordCounter.getWordNum();
				myPanel.setWordNum(wordNum);
			}
		});
		Main.undoManager = new UndoManager();
		this.getDocument().addUndoableEditListener(Main.undoManager);
	}
	private MyPanel myPanel;
	public void setMyPanel(MyPanel panel)
	{
		// TODO 自动生成的方法存根
		myPanel = panel;
	}
}
